# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=cordova
pkgver=12.0.0
pkgrel=1
pkgdesc='Cordova command line interface tool'
arch=('any')
url='https://cordova.apache.org'
license=('Apache')
depends=('node-gyp' 'nodejs-nopt' 'npm' 'semver')
install=cordova.install
source=("https://registry.npmjs.org/$pkgname/-/$pkgname-$pkgver.tgz")
noextract=("$pkgname-$pkgver.tgz")
sha512sums=('0f48060ec69796669f5b1559131268ea33bc00454b6017b5d908218f1e33cfc5df3614947b77089e6e13c83668c41da11689bbdde2f121ba2660e6f427ab6eb7')

package() {
  npm install -g --prefix "$pkgdir"/usr "$srcdir"/$pkgname-$pkgver.tgz

  # Non-deterministic race in npm gives 777 permissions to random directories.
  # See https://github.com/npm/npm/issues/9359 for details.
  chmod -R u=rwX,go=rX "$pkgdir"

  # npm installs package.json owned by build user
  # https://bugs.archlinux.org/task/63396
  chown -R root:root "$pkgdir"

  # Delete npm installed pyc files
  find "$pkgdir" -name "*.pyc" -delete

  # Experimental dedup
  rm -r "$pkgdir"/usr/lib/node_modules/$pkgname/node_modules/{,.bin/}node-gyp
  rm -r "$pkgdir"/usr/lib/node_modules/$pkgname/node_modules/{,.bin/}nopt
  rm -r "$pkgdir"/usr/lib/node_modules/$pkgname/node_modules/{,.bin/}semver
}
